/**
  * @file	systick.c
  *	@author	yoyoyes
  * @date	2023-5-31
  */
  
#include "systick.h"

/**
  * @func	gd_hal_systick_init
  * @param	none
  * @return	none
  */
void gd_hal_systick_init(void)
{
	systick_clksource_set(SYSTICK_CLKSOURCE_HCLK);
}

/**
  * @func	systick_delay_us
  * @param	us	微秒数值
  * @return	none
  */
void systick_delay_us(uint32_t us)
{
	SysTick->LOAD = us * 108;							
	SysTick->VAL = 0;								
	SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;		
	while(!(SysTick->CTRL & (1 << 16)));			
	SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;		
}

/**
  * @func	systick_delay_ms
  * @param	us	毫秒数值
  * @return	none
  */
void systick_delay_ms(uint32_t ms)
{
	while(ms-- != 0)
	{
		systick_delay_us(1000);
	}		
}
